<?php

abstract class AdnLibraryTable extends Zend_Db_Table_Abstract
{
	protected static $_loadedForms = array();
    const DEFAULT_FORM = 'Default';

    public function __construct($config = array())
    {
        $class = explode(' ', get_class($this));
        $rowClass = 'Object' . substr(array_pop($class), 0, -1);
        if (!class_exists($rowClass)) 
		{
            // Class $rowClass not found
        }
        $config   = array_merge($config, array(self::ROW_CLASS=>$rowClass));
        parent::__construct($config);
    }
    
    public function getForm($form = null)
    {
        $form = ucfirst(strtolower($form));
        
        if ($form == null) 
		{
            $form = self::DEFAULT_FORM;
        }
        
        $className = "Form" . ucfirst($this->_name) . $form;
        
        if (array_key_exists($className, self::$_loadedForms)) 
		{
            return self::$_loadedForms[$className];
        }
        
        if (class_exists($className, true)) 
		{
            self::$_loadedForms[$className] = new $className;
            return self::$_loadedForms[$className];
        } else 
		{
            // "Class $className not found"
        }
    }
    
    public function __call($meth, $args)
    {
        if (preg_match('|get(\w+)Form|', $meth, $matches)) 
		{
            return $this->getForm($matches[1]);
        }
    }
}

?>